<?php
namespace kernel\library;

class Handler
{
    public static function exception($exception){
        $errorCode = $exception->getCode();
        $res = [
            'errorcode' => $errorCode,
            'errormsg' => $exception->getMessage(),
            'errorfile' => $exception->getFile(),
            'errorline' => $exception->getLine(),
            'data' => [
                //'exception' => $exception->__toString()
            ],
            'time' => $_SERVER['REQUEST_TIME_FLOAT'],
            'runtime' => microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'],
            'use_memory' => memory_get_usage() - $_SERVER['BASICS_START_MEMORY'],
            'peak_memory' => memory_get_peak_usage()
        ];
        $httpCode = $errorCode;
        if($httpCode >= 10000){
            $httpCode = 419;//其他代码有可能是框架的
        }elseif($httpCode > 500){
            $httpCode = 429;//其他代码有可能是框架的
        }
        return Response::json($res, $httpCode);
    }
}

